package com.fanshuai.springcloud.service;

import com.fanshuai.springcloud.domain.User;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class UserService {
    List<User> list = new ArrayList<>();

    public List<User> list() {
        return list;
    }

    public User get(long userId) {
        return list.stream().filter(user -> {
            return user.getId() == userId;
        }).findFirst().orElse(null);
    }

    public void add(User user) {
        list.add(user);
    }

    public void delete(long userId) {
        list = list.stream().filter(user -> {
            return user.getId() == userId;
        }).collect(Collectors.toList());
    }
}
